﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommonTagTime;
using CommonTagTime.Business;
using CommonTagTime.ModelObject;
using System.IO;
public partial class ucProductItem : System.Web.UI.UserControl
{
    private Product product;
    private int categoryID;
    private int _Type;
    public int CategoryID
    {
        get
        {
            return categoryID;
        }
        set
        {
            categoryID = value;
        }
    }

    public int Type
    {
        get
        {
            return _Type;
        }
        set
        {
            _Type = value;
        }
    }


    public Product ProductItem
    {
        get
        {
            return product;
        }
        set
        {
            product = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (_Type > 0)
            {
                product.ShortDescription = string.Empty;
            }
            else
            {
                if (product.ShortDescription.Length > 150)
                    product.ShortDescription = clsString.BriefDescription(product.ShortDescription, 150);
            }
        }
    }

    public string ShowStatus()
    {
        string str = string.Empty;
        if (product.Status == 0)
        {
            str = @" - <span class=""comming"">sắp về</span>";
        }
        else if (product.Status == 2)
        {
            str = @" - <span class=""end"">hết hàng</span>";
        }
        return str;

    }

    public string CreateImageTab()
    {
        string imagePage = clsConfigData.DEFAULT_UPLOAD_PRODUCT_THUMBL_NOIMAGE;
        string imageDes = string.Empty;
        busImageProduct objBus = new busImageProduct();
        ImageProductCollection lstImage = objBus.GetListByProductID(product.ProductID);
        if (lstImage != null && lstImage.Count > 0)
        {
            ImageProduct objImage = lstImage[0];
            if (objImage != null)
            {
                if (File.Exists(this.Page.Server.MapPath(clsConfigData.DEFAULT_UPLOAD_PRODUCT_THUMB_FOLDER + objImage.FileName)))
                    imagePage = clsConfigData.DEFAULT_UPLOAD_PRODUCT_THUMB_FOLDER + objImage.FileName;

                imageDes = objImage.Description;
                if (imageDes == string.Empty)
                    imageDes = product.Name;
            }
        }      

        return imagePage;
    }

    public string GetParamater()
    {
        if (categoryID > 0)
            return "/san-pham/" + clsText.ToSEO(product.Name) + "/" + product.ProductID;
        else
            return "/san-pham/" + clsText.ToSEO(product.Name) + "/" + product.ProductID;
    }
}